package com.gimi.cloud.bbp.manage.consumer.service.sys.impl;

import com.gimi.cloud.bbp.common.enums.ResponseCodeEnum;
import com.gimi.cloud.bbp.common.utils.reqhead.Response;
import com.gimi.cloud.bbp.dto.sys.SysAuthorityDTO;
import com.gimi.cloud.bbp.manage.consumer.feign.SystemFeignService;
import com.gimi.cloud.bbp.manage.consumer.service.sys.SysAuthorityService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 授权相关接口实现类
 *
 * @author wbj
 * @version 1.0
 * @Description
 * @create 2018-01-30
 **/
@Service
public class SysAuthorityServiceImpl implements SysAuthorityService {
    private static final Logger logger = LoggerFactory.getLogger(SysAuthorityServiceImpl.class);

    private SystemFeignService systemFeignService;

    @Autowired
    public SysAuthorityServiceImpl(SystemFeignService systemFeignService) {
        this.systemFeignService = systemFeignService;
    }

    @Override
    public Response roleMenus(HttpServletRequest request, HttpServletResponse response, SysAuthorityDTO authorityDTO) throws Exception {
        if(null == authorityDTO.getRoId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"角色id为空，获取菜单列表失败");
            return resp;
        }
        return systemFeignService.roleMenus(authorityDTO);
    }

    @Override
    public Response doAuth(HttpServletRequest request, HttpServletResponse response, SysAuthorityDTO sysAuthorityDTO) throws Exception {
        if(null == sysAuthorityDTO.getRoId()){
            Response resp = new Response();
            resp.setResponseCode(ResponseCodeEnum.NO_DATA,"角色id为空，授权失败");
            return resp;
        }
        return systemFeignService.doAuth(sysAuthorityDTO);
    }
}
